//
//  MatchDeteilViewController.m
//  BigToBig
//
//  Created by 毛丽媛 on 16/8/3.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "MatchDeteilViewController.h"
#import "DetailInfoCell.h"
#import "MatchTimeCell.h"
#import "MatchInvestorsView.h"
#import "AButtonTableViewCell.h"
#import "NoChooseProController.h"
#import "ChooseProController.h"

@interface MatchDeteilViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic , strong)UITableView *tableView;
@property (nonatomic,copy)NSString *info;
@property(nonatomic,copy)NSString *concept;
@property(nonatomic,strong)MatchInvestorsView *headView;
@property(nonatomic,strong)UIView *signUpView;
@property(nonatomic,strong)UITableView *signUpTableView;
@property(nonatomic,assign)BOOL *Selected;

@end

@implementation MatchDeteilViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setBackBar];
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"速配大厅";
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    self.navigationController.navigationBar.barTintColor = COLOR_RGBA(77, 155, 255, 1);
    self.view.backgroundColor=GRAYCOLOR;
    
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64)];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = NO;
    self.tableView.bounces = NO;
    self.tableView.backgroundColor = [UIColor colorWithWhite:0.938 alpha:1.000];
    
    self.tableView.showsVerticalScrollIndicator = NO;
    
    
    [self.tableView registerClass:[MatchTimeCell class] forCellReuseIdentifier:@"time"];
    [self.tableView registerClass:[DetailInfoCell class] forCellReuseIdentifier:@"cell"];
    [self.tableView registerClass:[DetailInfoCell class] forCellReuseIdentifier:@"second"];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"pro"];
    
    self.headView = [[MatchInvestorsView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 150)];
    self.headView.backgroundColor = [UIColor whiteColor];
    self.headView.headPic.image = [UIImage imageNamed:@"touxiang"];
    self.headView.name.text = @"楼先生";
    self.headView.identity.text = @"投资人";
    self.headView.position.text = @"云真视频云*CEO";
    self.headView.describe.text = @"努力做到最好,找到好的合作伙伴";
    self.headView.Investment.text = @"投资0个项目";
    self.headView.financing.text = @"已融资20万";
    self.headView.credit.text = @"信用值: 100";
    self.headView.firPic.image = [UIImage imageNamed:@"icon投资"];
    self.headView.secPic.image = [UIImage imageNamed:@"index融资"];
    self.headView.thirPic.image = [UIImage imageNamed:@"信用卡"];
    self.tableView.tableHeaderView = self.headView;
    
    [self createClickSignUp];
    
}

#pragma mark 点击报名创建View
- (void)createClickSignUp{
    self.signUpView = [[UIView alloc] initWithFrame:CGRectMake(0, -64, kScreenWidth, kScreenHeight)];
    self.signUpView.backgroundColor = COLOR_RGBA(25, 26, 27, 0.8);
    
    self.signUpTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,kScreenHeight/2 - 100, kScreenWidth , 200)];
    self.signUpTableView.backgroundColor = [UIColor whiteColor];
    self.signUpTableView.delegate = self;
    self.signUpTableView.dataSource = self;
    
    [self.signUpView addSubview:self.signUpTableView];
    
    [self.signUpTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"SignUp"];
    [self.signUpTableView registerClass:[AButtonTableViewCell class] forCellReuseIdentifier:@"btn"];
    
    
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if (tableView == self.tableView) {
        
//        if (<#condition#>) {
//            return 3;
//        }
         return 4;
    }else {
        return 2;
    }
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (tableView == self.tableView) {
        return 40;
    }
    return 0.001f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (tableView == self.tableView) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
        view.backgroundColor = [UIColor colorWithWhite:0.949 alpha:1.000];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 50)];
        titleLabel.textColor = [UIColor blackColor];
        titleLabel.numberOfLines = 0;
        titleLabel.font = [UIFont systemFontOfSize:14];
        [view addSubview:titleLabel];
        //创业者
//        if (section == 0) {
//            titleLabel.text = @"速配时间";
//        }if (section == 1) {
//            titleLabel.text = @"投资理念";
//        }if (section == 2) {
//            titleLabel.text = @"投资人介绍";
//        }
        
        
            //投资人
            if (section == 0) {
                titleLabel.text = @"速配时间";
            }if (section == 1) {
                titleLabel.text = @"选取速配项目 ";
            }if (section == 2) {
                titleLabel.text = @"投资理念";
            }if (section == 3) {
                titleLabel.text = @"投资人介绍";
            }
        
        return view;
    }
        return 0;
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == self.tableView) {
        //创业者
//        return 1;
        
        //投资人
        if (section == 1) {
            
            return 2;
        }
        return 1;
        
    }else{
        if (section == 0) {
            return 2;
        }
            return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    tableView.separatorStyle = YES;
    if (tableView == self.tableView) {
//创业者
//        if (indexPath.section == 0) {
//            MatchTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"time" forIndexPath:indexPath];
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            
//            [cell.time1 addTarget:self action:@selector(time1:) forControlEvents:(UIControlEventTouchUpInside)];
//            [cell.time2 addTarget:self action:@selector(time1:) forControlEvents:(UIControlEventTouchUpInside)];
//            [cell.time3 addTarget:self action:@selector(time1:) forControlEvents:(UIControlEventTouchUpInside)];
//            [cell.time4 addTarget:self action:@selector(time1:) forControlEvents:(UIControlEventTouchUpInside)];
//            
//            return cell;
//        }if (indexPath.section == 1) {
//            DetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
//            self.info = @"这个人很懒,投资理念还没有写哦~";
//            cell.infoLabel.text = self.info;
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//        }else{
//            DetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"second" forIndexPath:indexPath];
//            self.concept = @"我愿意成为第一个相信创业梦想的人.我的投资不仅是提供早期资金支持,更主要的是成为川业者的创业伙伴,和创业团队一起选定方向,打磨产品,介绍资源";
//            cell.infoLabel.text = self.concept;
//            cell.selectionStyle = UITableViewCellSelectionStyleNone;
//            return cell;
//        }
        
        //投资人
        if (indexPath.section == 0) {
            MatchTimeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"time" forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            cell.time1.layer.borderColor = [COLOR_RGBA(217, 217, 217, 1) CGColor];
            
            [cell.time1 setTitleColor:[UIColor colorWithRed:0.323 green:0.639 blue:1.000 alpha:1.000] forState:UIControlStateSelected];
            
            cell.time2.layer.borderColor = [COLOR_RGBA(217, 217, 217, 1) CGColor];
            
            [cell.time2 setTitleColor:[UIColor colorWithRed:0.323 green:0.639 blue:1.000 alpha:1.000] forState:UIControlStateSelected];
            
            cell.time3.layer.borderColor = [COLOR_RGBA(217, 217, 217, 1) CGColor];
            
            [cell.time3 setTitleColor:[UIColor colorWithRed:0.323 green:0.639 blue:1.000 alpha:1.000] forState:UIControlStateSelected];
            
            cell.time4.layer.borderColor = [COLOR_RGBA(217, 217, 217, 1) CGColor];
            
            [cell.time4 setTitleColor:[UIColor colorWithRed:0.323 green:0.639 blue:1.000 alpha:1.000] forState:UIControlStateSelected];
            
            [cell.time1 addTarget:self action:@selector(time1:) forControlEvents:(UIControlEventTouchUpInside)];
            [cell.time2 addTarget:self action:@selector(time1:) forControlEvents:(UIControlEventTouchUpInside)];
            [cell.time3 addTarget:self action:@selector(time1:) forControlEvents:(UIControlEventTouchUpInside)];
            [cell.time4 addTarget:self action:@selector(time1:) forControlEvents:(UIControlEventTouchUpInside)];
            
            return cell;
        }if (indexPath.section == 1) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pro" forIndexPath:indexPath];
            NSArray *arr = [[NSArray alloc] initWithObjects:@"未选项目",@"已选项目", nil];
            
            UIButton *cyle = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth - 60, cell.contentView.frame.size.height/2 - 11, 22, 22)];
            cyle.titleLabel.font = [UIFont italicSystemFontOfSize:11];
            cyle.layer.cornerRadius = 11;
            cyle.backgroundColor = [UIColor redColor];
            
            [cyle setTitle:@"23" forState:UIControlStateNormal];
            [cyle setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            
            cell.textLabel.text = arr[indexPath.row];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell.contentView addSubview:cyle];
            
            return cell;
        }if (indexPath.section == 2) {
            DetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
            self.info = @"这个人很懒,投资理念还没有写哦~";
            cell.infoLabel.text = self.info;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            return cell;
        }else{
            DetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"second" forIndexPath:indexPath];
            self.concept = @"我愿意成为第一个相信创业梦想的人.我的投资不仅是提供早期资金支持,更主要的是成为川业者的创业伙伴,和创业团队一起选定方向,打磨产品,介绍资源";
            cell.infoLabel.text = self.concept;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell bringSubviewToFront:cell.contentView];
            return cell;
        }

    }
    
        
        if (indexPath.section == 0) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SignUp" forIndexPath:indexPath];
            NSArray *arr = [[NSArray alloc] initWithObjects:@"请选择秀券",@"请选择一个项目", nil];
             NSArray *lastArr = [[NSArray alloc] initWithObjects:@"已选",@"好的水杯", nil];
            
            
            cell.textLabel.text = arr[indexPath.row];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
           
            UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 20,cell.contentView.frame.size.height/2 - 15 , kScreenWidth / 2 - 10, 30)];
            contentLabel.text = lastArr[indexPath.row];
            contentLabel.textAlignment = NSTextAlignmentRight;
            contentLabel.font = [UIFont systemFontOfSize:15];
            contentLabel.textColor = [UIColor colorWithWhite:0.827 alpha:1.000];
            [cell.contentView addSubview:contentLabel];

            return cell;
        }else{
            AButtonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"btn"];
            [cell.sureBtn setTitle:@"确认报名" forState:UIControlStateNormal];
             cell.selectionStyle = UITableViewCellSelectionStyleNone;
            [cell.sureBtn addTarget:self action:@selector(sureSignUp:) forControlEvents:(UIControlEventTouchUpInside)];
            return cell;
        }
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.tableView) {
        if (indexPath.section == 1) {
            if (indexPath.row == 0) {
                NoChooseProController *noProVC = [[NoChooseProController alloc] init];
                [self.navigationController pushViewController:noProVC animated:YES];

            }if (indexPath.row == 1) {
                ChooseProController *chooseVC = [[ChooseProController alloc] init];
                [self.navigationController pushViewController:chooseVC animated:YES];
            }
            
        }
    }
}

- (void)sureSignUp:(UIButton *)btn{
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)time1:(UIButton *)btn{
    
    btn.selected = !btn.selected;
    
    if (btn.selected) {
        btn.layer.borderColor = [COLOR_RGBA(159, 201, 255, 1) CGColor];
    }else{
        btn.layer.borderColor = [COLOR_RGBA(217, 217, 217, 1) CGColor];
    }
    
}

- (void)SaveMessage:(UIButton *)btn{


    [self.view addSubview:self.signUpView];
   
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.tableView) {
//        //创业者
//        if (indexPath.section == 1) {
//            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
//            // 根据文本的内容和文本的字体进行计算高度
//            // 参数一:告诉系统,文本显示的最大范围
//            CGFloat width = (self.view.frame.size.width - 40);
//            CGRect rect = [self.info boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
//            // 然后把图片的高和文本的高作为返回值返回
//            return rect.size.height + 20;
//        }if (indexPath.section == 2) {
//            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
//            // 根据文本的内容和文本的字体进行计算高度
//            // 参数一:告诉系统,文本显示的最大范围
//            CGFloat width = (self.view.frame.size.width - 40);
//            CGRect rect = [self.concept boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
//            // 然后把图片的高和文本的高作为返回值返回
//            return rect.size.height + 20;
//        }
//        else{
//            return 120;
//        }
//
//    }else{
//        return 200/3;
        
        //投资人
        //创业者
        if (indexPath.section == 1) {
            return 55;
        }
        if (indexPath.section == 2) {
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
            // 根据文本的内容和文本的字体进行计算高度
            // 参数一:告诉系统,文本显示的最大范围
            CGFloat width = (self.view.frame.size.width - 40);
            CGRect rect = [self.info boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
            // 然后把图片的高和文本的高作为返回值返回
            return rect.size.height + 20;
        }if (indexPath.section == 2) {
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14], NSFontAttributeName, nil];
            // 根据文本的内容和文本的字体进行计算高度
            // 参数一:告诉系统,文本显示的最大范围
            CGFloat width = (self.view.frame.size.width - 40);
            CGRect rect = [self.concept boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
            // 然后把图片的高和文本的高作为返回值返回
            return rect.size.height + 20;
        }
        else{
            return 120;
        }
        
    }else{
        return 200/3;

        
    }
}

#pragma mark 导航栏左右Button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
    UIButton *saveBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(kScreenWidth - 44,0 , 44, 44);
    [saveBtn addTarget:self action:@selector(SaveMessage:) forControlEvents:UIControlEventTouchUpInside];
    
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn setTitle:@"报名" forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:saveBtn];
    
}

- (void)backController:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = YES;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
